﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using socialnexus.classes.models;

namespace socialnexus
{
    public partial class EntryPointAuth : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            socialnexus.classes.models.EntryPoint ep;

            if (Request.Cookies.Get("EntryPoint") == null)
            {
                Response.Redirect("~/");
                return;
            }

            ep = socialnexus.classes.models.EntryPoint.GetByGUID(Request.Cookies.Get("EntryPoint").Values["GUID"]);
            if (ep == null)
            {
                Response.Redirect("~/");
                return;
            }

            if (Request.QueryString["UserId"] == null)
            {
                Response.Redirect("~/EntryPoint.aspx");
                return;
            }

            if (ep.getUserIds().Contains(Request.QueryString["UserId"].ToString()))
            {
                Session["user"] = SiteUser.GetById(Request.QueryString["UserId"].ToString());
                if (Session["user"] == null)
                {
                    Response.Redirect("~/EntryPoint.aspx");
                    return;
                }
                else
                {
                    Response.Redirect("~/Inbox.aspx");
                    return;
                }
            }
        }
    }
}
